home *** CD-ROM | disk | FTP | other *** search
- /* Constants and structure definitions */
-
- #define _MC68881_
-
- #include <stdio.h>
- #include <math.h>
-
- #define MaxLay 5
- #define ActiveNets 4
-
- /*---- return codes for linesearch ----*/
- #define LINEOK 0 /* if satisfactory new parm value found in linesearch */
- #define LINENOTOK 1 /* if linesearch can't find a step small enough to reduce SS */
-
- /*---- return codes for gradient methods ----*/
- #define FAIL 0 /* if current parm value is not an approximate critical point */
- #define METGRADTOL 1 /* if norm of scaled gradient less than gradtol */
- #define METSTEPTOL 2 /* if scaled step is less than steptol */
- #define LINEFAIL 4 /* if linesearch failed to find next parm distinct from current value */
- #define EXCEDITNLIM 8 /* if iteratation limit exceeded */
- #define SINGJAC 16 /* if Jacobian is singular */
- #define NETSAT 32 /* if network is possible oversaturated */
-
- /*---- codes used in Hooke & Jeeves search method ----*/
- #define CHANGED 1 /* if weight was changed in last search iteration */
-
- /*---- codes for type of network ----*/
- #define SigUB 1 /* code for unbiased Sigma network */
- #define SigB 2 /* biased Sigma network */
- #define Lin 3 /* Linear model */
-
- /* codes for squashing function */
- #define Logistic 1 /* logistic squashing function */
- #define hyperTan 2 /* hypebolic tangent */
- #define Thresh 3 /* threshold squashing function */
-
- /* codes for estimation method */
- #define BackProp 1 /* code for Back Propagation estimation method */
- #define SimAnn 2 /* Simulated annealing */
- #define GaussNew 3 /* Gauss Newton method */
- #define qGaussNew 4 /* quasi Gauss Newton method, corrects for singular Jacobian */
- #define qNewton 5 /* quasi Newton method */
- #define HookeJeeves 6 /* Hooke and Jeeves method for direct search */
-
- #define DataType double /* specify the type of data used */
-
- typedef struct /* type for a matrix of floating values */
- {
- int rows,cols;
- double ** cells;
- } DTypeMatrix;
-
- typedef struct /* type for a vector of floating values */
- {
- int rows;
- double ** cells;
- } DTypeVector;
-
- typedef struct /* type for neural network data structure */
- {
- unsigned int OutLayer; /* index of output layer in network, 1 less than # layers, must be less than MaxLayers */
- unsigned int Units[MaxLay]; /* number of units in each layer */
- DTypeMatrix W[MaxLay-1]; /* weight matrices for each layer except output */
- double gradtol; /* criteria for maximum used on gradient */
- double steptol; /* criteria for convergence used on parameter step */
- double maxstep; /* max step size, zero => no limit */
- double maxrelstep; /* max relative step permited */
- unsigned int itnlimit; /* limit on the number of iterations */
- short int usemaxstep; /* flag to impose max step limit on gradient methods */
- short int type; /* the type of network */
- short int method; /* method to use in estimating network */
- short int squash; /* squashing function to use */
- short int valid; /* FALSE if new network, TRUE if network has already been estimated */
- short int prtitinfo; /* flag to cause printing of estimates, etc. for each iteration */
- short int saveout; /* flag to cause save to file of all output */
- } NeuralNet;
-
- /*--------------------------- Prototypes ------------------------------*/
- /*---- Prototypes for Neural Network Main.c ----*/
- main(void);
- printf(char *, ...);
- FILE * fopen(char *,char *);
- fclose(FILE *);
- fprintf(FILE *, char *, ...);
- Estimate(void);
-
- /*---- Prototypes for General.c ----*/
- RestoreParms(DTypeVector *);
- SaveParms(DTypeVector *);
- NotYetAvail(void);
- HandleOutOfMem(void);
-
- do_HookeJeeves(void);
- ExMove(void);
- PatMove(void);
- SetInitStep(void);
- AllotSearchWorkSpace(void);
- LockSearchWorkSpace(void);
- UnlockSearchWorkSpace(void);
-
- /*---- Prototypes for Gradient methods.c ----*/
- do_GaussNewton(void);
- do_quasiGaussNewton(void);
- ComputegradSSforqGN(void);
- AppendResidZeros(void);
- AppendMuIdentity(void);
- LineSearch(double *);
- ConstrainStep(void);
- UpdateParms(DataType);
- StopYet(double,int,int);
- StopAtFirst(double);
- double Compute_minlambda(void);
- AllotGradientWorkSpace(void);
- LockGradientWorkSpace(void);
- UnlockGradientWorkSpace(void);
-
- /*---- Prototypes for Ord Least Squares.c ----*/
- OLSbyQRmethod(DTypeMatrix *,DTypeVector *,DTypeVector *,DTypeVector *);
- ComputeQY(DTypeMatrix *,DTypeVector *,DTypeVector *);
- SolveRbY(DTypeMatrix *,DTypeVector *,DTypeVector *);
- QRDecomposition(DTypeMatrix *,DTypeVector *,DTypeVector *);
- WriteYXToFile(FILE *, DTypeVector *, DTypeMatrix * );
-
- /*---- Prototypes for Compute_SS.c ----*/
- logisticSquash_dSquash(DTypeVector *,DTypeVector *);
- DataType ComputeOutputJac(void);
- ComputeJacobian(DataType *);
- double Compute_SS_Jac(void);
- logisticSquash(DTypeVector *);
- DataType ComputeOutputOnly(void);
- double Compute_SS(void);
- HLock_Alpha_dSquash(void);
- HUnlock_Alpha_dSquash(void);
- HLock_Alpha(void);
- HUnlock_Alpha(void);
-
- /*---- Prototypes for Setup Network.c ----*/
- SetupNetDefaults(void);
- AllotInitNewNetWeights(void);
- HLockNet(void);
- HUnlockNet(void);
- DisplayNet(void);
- InitWeights(DTypeMatrix *);
- SetupTolerances(void);
-
- /*---- Prototypes for DTypeMatrix.c ----*/
- AllotDTypeMatrix(DTypeMatrix *,int,int);
- DisplayDTypeMatrix(DTypeMatrix *);
- WriteMatrixToFile(FILE *,DTypeMatrix * );
- ClearDTypeMatrix(DTypeMatrix *);
- Matrix_by_Vec(DTypeMatrix *,DTypeVector *,DTypeVector *);
- Matrix_by_Diag(DTypeMatrix *,DTypeVector *,DTypeMatrix *);
- Matrix_by_Matrix(DTypeMatrix *,DTypeMatrix *,DTypeMatrix *);
-
- /*---- Prototypes for DTypeVector.c ----*/
- double L2Norm(DTypeVector *);
- DataType Vec_by_Vec(DTypeVector *,DTypeVector *);
- CopyDTypeVector(DTypeVector *,DTypeVector *);
- AllotDTypeVector(DTypeVector *,int);
- DisplayDTypeVector(DTypeVector *);
- WriteVectorToFile(FILE *,DTypeVector *);
- ClearDTypeVector(DTypeVector *);
-
- /*---- Prototypes for testdata.c ----*/
- SetTestNet(NeuralNet *);
- testData(NeuralNet *);
- testJacobian(DTypeMatrix *,DTypeVector *,DTypeVector *,DTypeVector *);
- testdepdata(NeuralNet *);
-
-